package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-07-22
 * Time: 16:57
 */
public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书！");
        /**
         * 1.先找到这本书
         * 2.看该本书的状态是否被借阅
         *  2.1、借阅了，返回不能借阅
         *  2.2、未借阅，可以借阅，然后修改该书为已经借阅
         */

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅书的书名：");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book1 = bookList.getBook(i);
            if(book1.getName().equals(name)){//找到了这本书
                if(book1.isBorrowed() == false){
                    //没有被借阅
                    book1.setBorrowed(true);
                    System.out.println("该书借阅成功！");
                    return;
                }else {
                    System.out.println("该书已被借阅，不能被借出了！");
                    return;
                }

            }
        }
        System.out.println("没有找到你要借阅的图书！");
    }
}
